package cn.gmcx.lazy.izze.interceptor;

import cn.gmcx.lazy.izze.enums.RespCodeEnum;
import cn.gmcx.lazy.izze.exception.BizException;
import cn.gmcx.lazy.izze.utils.JwtUtils;;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;


@Configuration
public class GobleInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        try{
            JwtUtils.parseJwt(token);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            throw new BizException(RespCodeEnum.UNAUTHORIZE);
        }
    }
}
